package com.zhiyou100.pra;

/**
 * 矩形类
 *
 */
public class Rectangle {

    private double length; //长
    private double width; //宽

    //根据有参构造也可以访问私有属性
    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    public void setLength(double length){
        //此处可以添加对长度的验证
        this.length = length;
    }

    public void setWidth(double width){
        this.width = width;
    }

    public double getLength(){
        return length;
    }

    public double getWidth(){
        return width;
    }

    //计算面积
    public double getArea() {
        return length * width;
    }

    //计算周长
    public double getPer() {
        return 2 * (length + width);
    }

    //获取矩形的所有信息
    public void showAll() {
        //变量名.sout/soutv
        System.out.println("长 = " + length);
        System.out.println("宽 = " + width);
        System.out.println("面积 = " + getArea());
        double per = getPer();
        System.out.println("周长 = " + per);
    }

}
